package day10;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ReflectTest {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
        String className = "day10.ReflectDemo";
//        加载类
        Class cls = Class.forName(className);
//        进行实例化
        Object obj = cls.newInstance();
//        调用test方法
        Method method = cls.getDeclaredMethod("test");
//        执行方法
       Object returnVal =  method.invoke(obj);
        System.out.println(returnVal);
      method = cls.getDeclaredMethod("demo");
      method.setAccessible(true);//将私有成员的权限放开，破坏了封装
      returnVal = method.invoke(obj);
        System.out.println(returnVal);
    }
}
